package com.aier.service.purchase;

import com.aier.bean.common.CommonResult;
import com.aier.bean.common.GlobalCode;
import com.aier.bean.purchase.GoodsArrivedBean;
import com.aier.exception.CastException;
import com.aier.mapper.purchase.GoodsArrivedMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 到货service
 */

@Service
public class GoodsArrivedService {

    @Resource
    private GoodsArrivedMapper goodsArrivedMapper;

    /**
     * 根据合同编号获取到货信息
     * @param contractCode
     * @return
     */
    public List<GoodsArrivedBean> getGoodsArrivedByContractCode(String contractCode){
        List<GoodsArrivedBean> goodsArrivedBeanList = new ArrayList<>();
        try {
            goodsArrivedBeanList = goodsArrivedMapper.selectGoodsArrivedByContractCode(contractCode);
        }catch (Exception e){
            e.printStackTrace();
            CastException.cast(GlobalCode.GET_GOODS_ARRIVED_BY_CONTRACT_CODE_FAIL);
        }
        return goodsArrivedBeanList;
    }


    /**
     * 到货信息插入到货表
     * @param goodsArrivedBean
     */
    public CommonResult saveGoodsArrived(GoodsArrivedBean goodsArrivedBean){
        try {
            goodsArrivedMapper.insert(goodsArrivedBean);
        }catch (Exception e){
            e.printStackTrace();
            CastException.cast(GlobalCode.SAVE_GOODS_ARRIVED_FAIL);
        }
        return CommonResult.success();
    }

}
